package com.zc.timedown.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.zc.timedown.dto.*;
import com.zc.timedown.domain.AllStats;
import com.zc.timedown.domain.TodayPlan;
import com.zc.timedown.domain.TodayPlanItem;
import com.zc.timedown.vo.DailyCompletedStatisticsVo;
import com.zc.timedown.vo.TodayPlanItemVo;
import com.zc.timedown.vo.WeeklyPlanStatisticsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * 今日计划Mapper接口
 *
 * @author zc
 * @date 2025-09-30
 */
@Mapper
public interface TodayPlanMapper extends BaseMapper<TodayPlan>
{
    /**
     * 查询今日计划
     *
     * @param id 今日计划主键
     * @return 今日计划
     */
    public TodayPlan selectTodayPlanById(Long id);

    /**
     * 查询今日计划列表
     *
     * @param todayPlan 今日计划
     * @return 今日计划集合
     */
    public List<TodayPlan> selectTodayPlanList(TodayPlan todayPlan);

    /**
     * 新增今日计划
     *
     * @param todayPlan 今日计划
     * @return 结果
     */
    public int insertTodayPlan(TodayPlan todayPlan);

    /**
     * 修改今日计划
     *
     * @param todayPlan 今日计划
     * @return 结果
     */
    public int updateTodayPlan(TodayPlan todayPlan);

    /**
     * 删除今日计划
     *
     * @param id 今日计划主键
     * @return 结果
     */
    public int deleteTodayPlanById(Long id);

    /**
     * 批量删除今日计划
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTodayPlanByIds(Long[] ids);

        /**
         * 批量删除今日计划子项明细
         *
         * @param ids 需要删除的数据主键集合
         * @return 结果
         */
        public int deleteTodayPlanItemByGoalIds(Long[] ids);

        /**
         * 批量新增今日计划子项明细
         *
         * @param todayPlanItemList 今日计划子项明细列表
         * @return 结果
         */
        public int batchTodayPlanItem(List<TodayPlanItem> todayPlanItemList);


        /**
         * 通过今日计划主键删除今日计划子项明细信息
         *
         * @param id 今日计划ID
         * @return 结果
         */
        public int deleteTodayPlanItemByGoalId(Long id);

        /**
         * 查询今日计划子项明细列表
         *
         * @param todayPlanItem 今日计划子项明细
         * @return 今日计划子项明细集合
         */
        public List<TodayPlanItem> selectTodayPlanItemList(TodayPlanItem todayPlanItem);

    /**
     * 根据ID和日期查询今日计划及子项
     */
    List<TodayPlanItemVo> selectTodayPlanByIdAndDate(@Param("id") Long id);

    /**
     * 修改今日计划子项
     */
    int updateTodayPlanItem(TodayPlanItemDto todayPlan);

    /**
     * 删除今日计划子项
     */
    int deleteTodayPlanItem(Long id);


    List<WeeklyPlanStatisticsVo> selectWeeklyPlanStatistics(Long userId);

    List<DailyCompletedStatisticsVo> selectMonthlyCompletedStatistics(Long userId);

    List<WeeklyStatsDTO> selectRecent4WeeksStats(Long userId);

    AllStats selectAllClockInStats(Long userId);

    List<MonthlyStatsDTO> selectMonthlyClockInStatsByMonth(@Param("userId") Long userId,
                                                           @Param("year") Integer year,
                                                           @Param("month") Integer month);

    /**
     * 查询指定时间范围内的统计数据
     */
    TimeRangeStatisticsDto selectTimeRangeStats(@Param("userId") Long userId,
                                                @Param("startDate") String startDate,
                                                @Param("endDate") String endDate);

    List<DailyPlanStatisticsDto> selectDailyPlanStatistics(@Param("userId") Long userId,
                                                           @Param("startDate") String startDate,
                                                           @Param("endDate") String endDate);


    /**
     * 根据用户ID和日期查询计划
     */
    @Select("SELECT * FROM today_plan WHERE user_id = #{userId} AND plan_date = #{planDate}")
    TodayPlan selectByUserIdAndDate(@Param("userId") Long userId, @Param("planDate") LocalDate planDate);

}